home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / falcon / programm.ing / nt_dsp1.lzh / NT_DSP1.MSA / FFT / FFTR2AA.ASM < prev    next >
Assembly Source File  |  1990-01-17  |  3KB  |  122 lines

  1.     page    132,60,1,1
  2. fftr2aa    macro    points,data,coef
  3. fftr2aa    ident    1,2
  4. ; This routine can be used with automatic scaling down turned on
  5. ; (S1=0, S0=1). In that case, place the (real) input data in the
  6. ; high portion of the accumulator.
  7. ; Radix 2 Decimation in Time In-Place Fast Fourier Transform Routine
  8. ;
  9. ;    Complex input and output data
  10. ;        Real data in X memory
  11. ;        Imaginary data in Y memory
  12. ;    Normally ordered input data
  13. ;    Bit reversed output data
  14. ;    Coefficient lookup table
  15. ;        -Cosine value in X memory
  16. ;        -Sine value in Y memory
  17. ;
  18. ; Macro Call - fftr2a   points,data,coef
  19. ;
  20. ;    points     number of points (2-32768, power of 2)
  21. ;    data       start of data buffer
  22. ;    coef       start of sine/cosine table
  23. ;
  24. ; Alters Data ALU Registers
  25. ;    x1    x0    y1    y0
  26. ;    a2    a1    a0    a
  27. ;    b2    b1    b0    b
  28. ;
  29. ; Alters Address Registers
  30. ;    r0    n0    m0
  31. ;    r1    n1    m1
  32. ;    r2    n2
  33. ;
  34. ;    r4    n4    m4
  35. ;    r5    n5    m5
  36. ;    r6    n6    m6
  37. ;
  38. ; Alters Program Control Registers
  39. ;    pc    sr
  40. ;
  41. ; Uses 6 locations on System Stack
  42. ;
  43. ; Tested and verified - April 4, 1988
  44. ;
  45.     move     #points/2,n1    ;initialize butterflies per group
  46.     move    #1,n2        ;initialize groups per pass
  47.     move    #points/4,n6    ;initialize C pointer offset
  48.     move    #-1,m0        ;initialize A and B address modifiers
  49.     move    m0,m1        ;for linear addressing
  50.     move    m0,m2
  51.     move    m0,m4
  52.     move    m0,m5
  53.     move    #0,m6        ;initialize C address modifier for
  54.                 ;reverse carry (bit-reversed) addressing
  55. ;
  56. ; Perform all FFT passes except last pass with triple nested DO loop
  57. ;
  58.     do    #@cvi(@log(points)/@log(2)-0.5),_end_pass
  59.     move    #data,r0    ;initialize A input pointer
  60.     move    r0,r1
  61.     move    n1,r2
  62.     move    r0,r4        ;initialize A output pointer
  63.     move    (r1)+n1        ;initialize B input pointer
  64.     move    r1,r5        ;initialize B output pointer
  65.     move    #coef,r6    ;initialize C input pointer
  66.     lua    (r2)+,n0    ;initialize pointer offsets
  67.     move    n0,n4
  68.     move    n0,n5
  69.     move    (r2)-        ;butterfly loop count
  70.     move    x:(r1),x1    y:(r6),y0    ;lookup -sine and -cosine values
  71.     move    x:(r6)+n6,x0    y:(r0),b    ;update C pointer, preload data
  72.     mac    x1,y0,b        y:(r1)+,y1
  73.     macr    -x0,y1,b    y:(r0),a
  74.  
  75.     do    n2,_end_grp
  76.     do    r2,_end_bfy
  77.     subl    b,a        x:(r0),b    b,y:(r4)    ;Radix 2 DIT butterfly kernel
  78.     mac    -x1,x0,b    x:(r0)+,a    a,y:(r5)
  79.     macr    -y1,y0,b    x:(r1),x1
  80.     subl    b,a        b,x:(r4)+    y:(r0),b
  81.     mac    x1,y0,b                y:(r1)+,y1
  82.     macr    -x0,y1,b    a,x:(r5)+    y:(r0),a
  83. _end_bfy
  84.     move    (r1)+n1
  85.     subl    b,a        x:(r0),b    b,y:(r4)
  86.     mac    -x1,x0,b    x:(r0)+n0,a    a,y:(r5)
  87.     macr    -y1,y0,b    x:(r1),x1    y:(r6),y0
  88.     subl    b,a        b,x:(r4)+n4    y:(r0),b
  89.     mac    x1,y0,b        x:(r6)+n6,x0    y:(r1)+,y1
  90.     macr    -x0,y1,b    a,x:(r5)+n5    y:(r0),a
  91. _end_grp
  92.     move    n1,b1
  93.     lsr    b    n2,a1    ;divide butterflies per group by two
  94.     lsl    a    b1,n1    ;multiply groups per pass by two
  95.     move    a1,n2
  96. _end_pass
  97. ;
  98. ; Do last FFT pass
  99. ;
  100.     move    #2,n0        ;initialize pointer offsets
  101.     move    n0,n1
  102.     move    n0,n4
  103.     move    n0,n5
  104.     move    #data,r0    ;initialize A input pointer
  105.     move    r0,r4        ;initialize A output pointer
  106.     lua    (r0)+,r1    ;initialize B input pointer
  107.     move    #coef,r6    ;initialize C input pointer
  108.     lua    (r1)-n1,r5    ;initialize B output pointer
  109.     move    x:(r1),x1    y:(r6),y0
  110.     move    x:(r5),a    y:(r0),b
  111.  
  112.     do    n2,_lastpass
  113.     mac    x1,y0,b    x:(r6)+n6,x0    y:(r1)+n1,y1    ;Radix 2 DIT butterfly kernel
  114.     macr    -x0,y1,b    a,x:(r5)+n5    y:(r0),a    ;with one butterfly per group
  115.     subl    b,a    x:(r0),b    b,y:(r4)
  116.     mac    -x1,x0,b    x:(r0)+n0,a    a,y:(r5)
  117.     macr    -y1,y0,b    x:(r1),x1    y:(r6),y0
  118.     subl    b,a        b,x:(r4)+n4    y:(r0),b
  119. _lastpass
  120.     move    a,x:(r5)+n5
  121.     endm
  122.